class MinStack:

    def __init__(self):
        #初始化一个空的栈
        self.stack=[]
        #设置当前栈中的最小值
        self.min=None

    def push(self, val):
        #将数据压入栈
        self.stack.append(val)
        if self.min==None or self.min>val:
            self.min=val

    def pop(self):
        popElem=self.stack.pop()
        if popElem==self.min:
            #最小值从栈中弹出了
            self.min=None
            for i in self.stack:
                if self.min==None or self.min>i:
                    self.min=i
        return popElem

    def top(self):
        #返回栈底元素值
        return self.stack[0]

    def getMin(self):
        return self.min
# Your MinStack object will be instantiated and called as such:
# obj = MinStack()
# obj.push(val)
# obj.pop()
# param_3 = obj.top()
# param_4 = obj.getMin()